<template>
  <promoter v-if="nodeConfig.type === 0" v-model="nodeConfig"></promoter>

  <approver v-if="nodeConfig.type === 1" v-model="nodeConfig"></approver>

  <send v-if="nodeConfig.type === 2" v-model="nodeConfig"></send>

  <branch v-if="nodeConfig.type === 4" v-model="nodeConfig">
    <template v-slot="slot">
      <node-wrap v-if="slot.node" v-model="slot.node.childNode"></node-wrap>
    </template>
  </branch>

  <node-wrap v-if="nodeConfig.childNode" v-model="nodeConfig.childNode"></node-wrap>

</template>

<script setup name="NodeWrap">
import Approver from './nodes/approver'
import Promoter from './nodes/promoter'
import Branch from './nodes/branch'
import Send from './nodes/send'

// 接收参数
const props = defineProps({
  modelValue: {
    type: Object, default: () => {
    }
  }
})

// 定义事件
const emit = defineEmits(['update:modelValue'])

// 定义数据
const nodeConfig = ref({});
nodeConfig.value = props.modelValue;

// 监听传入参数变化
watch(() => props.modelValue, (nVal) => {
  nodeConfig.value = nVal
});
// 监听数据变化
watch(() => nodeConfig.value, (nVal) => {
  emit('update:modelValue', nVal);
});

</script>

<style>
</style>
